<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

/**
 * TYPOlight webCMS
 *
 * The TYPOlight webCMS is an accessible web content management system that 
 * specializes in accessibility and generates W3C-compliant HTML code. It 
 * provides a wide range of functionality to develop professional websites 
 * including a built-in search engine, form generator, file and user manager, 
 * CSS engine, multi-language support and many more. For more information and 
 * additional TYPOlight applications like the TYPOlight MVC Framework please 
 * visit the project website http://www.typolight.org.
 *
 * PHP version 5
 * @copyright  Martin Komara 2007 
 * @author     Martin Komara 
 * @package    CatalogModule 
 * @license    GPL 
 * @filesource
 */


/**
 * Class ModuleSlidesCategory 
 *
 * @copyright  Martin Komara 2007 
 * @author     Martin Komara 
 * @package    Catalog
 */
class ModuleSlidesCategory extends Module
{
    /**
	 * Template
	 * @var string
	 */
	protected $strTemplate = 'mod_slides_category';
	
	/**
	 * Display a wildcard in the back end
	 * @return string
	 */
	public function generate()
	{
		if (TL_MODE == 'BE')
		{
			$objTemplate = new BackendTemplate('be_wildcard');

			$objTemplate->wildcard = '### SLIDES CATEGORY ###';
			$objTemplate->title = $this->name;
			$objTemplate->id = $this->id;
			$objTemplate->link = $this->alias;
			$objTemplate->href = 'typolight/main.php?do=Product catalog&amp;table=tl_catalog_items&amp;act=edit&amp;id=' . $this->id;

			return $objTemplate->parse();
		}
		
		return parent::generate();
	}


	/**
	 * Generate module
	 */
	protected function compile()
	{
		if ((isset($_GET['tag']) && $_GET['tag']) || (isset($_GET['brand']) && $_GET['brand'])) return;
		$this->import("Database");
		if (!isset($_GET['category']) || !$_GET['category'])
		{
			// homepage slides
			$obj_slides = $this->Database->prepare("SELECT * FROM `tl_slides` WHERE `is_in_home`='homepage' AND `published`=1")
										->execute(time());
			$this->Template->slides_dir = $obj_slides->singleSRC;			
		}
		else
		{
			$obj_slides = $this->Database->prepare("SELECT * FROM `tl_slides` WHERE `is_in_home`='category' AND `id_category`=? AND `published`=1")
										->execute($_GET['category']);
			$this->Template->slides_dir = $obj_slides->singleSRC;
		}
		
		if (is_dir($this->Template->slides_dir)){
			$tmp = scandir($this->Template->slides_dir);
			foreach ($tmp as $file){				
				if (!is_dir($file)&&$file!="Thumbs.db"){
					$slides_arr[] = $file;
				}
			}
			$this->Template->slides_arr = $slides_arr;
		}
		if ($obj_slides->links){
			$this->Template->links = explode(';',$obj_slides->links);
		}
	}
}

?>